﻿using System.Drawing.Imaging;
using System.Drawing;

namespace AutoMail.QuartzJobs.Jobs.Utils
{
    public static class PictureBase64Generating
    {
        /// <summary>
        /// Get Brithday Mail template picture base64 string
        /// </summary>
        /// <param name="staffName"> staff name </param>
        /// <param name="mailSendDate">DateTime.Now.ToShortDateString()</param>
        /// <returns></returns>
        public static string GetBirthDayMailTemplatePictureBase64String(string staffName, string mailSendDate, 
            string fontName = "Arial", short fontSize = 16)
        {
            // Load the image from file
            string imagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "QuartzJobs\\Jobs\\images", "BirthdayCongratulation.jpg");
            Image image = Image.FromFile(imagePath);

            // Create a graphics object from the image
            Graphics graphics = Graphics.FromImage(image);

            // Define the font and brush for the text
            Font font = new Font(fontName, fontSize);
            Brush brush = new SolidBrush(Color.Black);

            // Define the position for Staff name showing
            int x1 = 803;
            int y1 = 785;

            // Draw the text onto the image
            graphics.DrawString(staffName, font, brush, x1, y1);

            // Define the position for date info showing
            int x2 = 1190;
            int y2 = 2265;

            // Draw the text onto the image
            graphics.DrawString(mailSendDate, font, brush, x2, y2);

            // Save the modified image to a memory stream
            MemoryStream memoryStream = new MemoryStream();
            image.Save(memoryStream, ImageFormat.Jpeg);

            // Convert the image to base64
            string base64String = Convert.ToBase64String(memoryStream.ToArray());
            return base64String;
        }

        /// <summary>
        /// Get Brithday Mail template picture base64 string
        /// </summary>
        /// <param name="staffName"> staff name </param>
        /// <param name="mailSendDate">DateTime.Now.ToShortDateString()</param>
        /// <returns></returns>
        public static string GetAnniversaryMailTemplatePictureBase64String1(string staffName, string anniversaryYears, string mailSendDate,
            string fontName = "Arial")
        {
            // Load the image from file
            string imagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "QuartzJobs\\Jobs\\images", "AnniversaryCongratulation1.jpeg");
            Image image = Image.FromFile(imagePath);

            // Create a graphics object from the image
            Graphics graphics = Graphics.FromImage(image);

            // Define the font and brush for the text
            Font font1 = new Font(fontName, 8);
            Brush brush1 = new SolidBrush(Color.Black);

            // Define the position for Staff name showing
            int x1 = 145;
            int y1 = 322;

            // Draw the text onto the image
            graphics.DrawString(staffName, font1, brush1, x1, y1);

            // Define the font and brush for the text
            Font font2 = new Font(fontName, 8);
            Brush brush2 = new SolidBrush(Color.Black);

            // Define the position for date info showing
            int x2 = 424;
            int y2 = 428;

            // Draw the text onto the image
            graphics.DrawString(anniversaryYears, font2, brush2, x2, y2);

            // Define the font and brush for the text
            Font font3 = new Font(fontName, 8);
            Brush brush3 = new SolidBrush(Color.Black);
            // Define the position for date info showing
            int x3 = 412;
            int y3 = 1043;

            // Draw the text onto the image
            graphics.DrawString(mailSendDate, font3, brush3, x3, y3);

            // Save the modified image to a memory stream
            MemoryStream memoryStream = new MemoryStream();
            image.Save(memoryStream, ImageFormat.Jpeg);

            // Convert the image to base64
            string base64String = Convert.ToBase64String(memoryStream.ToArray());
            return base64String;
        }

        /// <summary>
        /// Get Brithday Mail template picture base64 string
        /// </summary>
        /// <param name="staffName"> staff name </param>
        /// <param name="mailSendDate">DateTime.Now.ToShortDateString()</param>
        /// <returns></returns>
        public static string GetAnniversaryMailTemplatePictureBase64String2(string staffName, string anniversaryYears, string mailSendDate,
            string fontName = "Arial")
        {
            // Load the image from file
            string imagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "QuartzJobs\\Jobs\\images", "AnniversaryCongratulation2.jpeg");
            Image image = Image.FromFile(imagePath);

            // Create a graphics object from the image
            Graphics graphics = Graphics.FromImage(image);

            // Define the font and brush for the text
            Font font1 = new Font(fontName, 8);
            Brush brush1 = new SolidBrush(Color.Black);

            // Define the position for Staff name showing
            int x1 = 145;
            int y1 = 322;

            // Draw the text onto the image
            graphics.DrawString(staffName, font1, brush1, x1, y1);

            // Define the font and brush for the text
            Font font2 = new Font(fontName, 8);
            Brush brush2 = new SolidBrush(Color.Black);

            // Define the position for date info showing
            int x2 = 424;
            int y2 = 428;

            // Draw the text onto the image
            graphics.DrawString(anniversaryYears, font2, brush2, x2, y2);

            // Define the font and brush for the text
            Font font3 = new Font(fontName, 8);
            Brush brush3 = new SolidBrush(Color.Black);
            // Define the position for date info showing
            int x3 = 412;
            int y3 = 1043;

            // Draw the text onto the image
            graphics.DrawString(mailSendDate, font3, brush3, x3, y3);

            // Define the font and brush for the text
            Font font4 = new Font("Arial", 15);
            Brush brush4 = new SolidBrush(Color.Black);
            // Define the position for date info showing
            int x4 = 286;
            int y4 = 248;

            // Draw the text onto the image
            graphics.DrawString(anniversaryYears, font4, brush4, x4, y4);

            // Save the modified image to a memory stream
            MemoryStream memoryStream = new MemoryStream();
            image.Save(memoryStream, ImageFormat.Jpeg);

            // Convert the image to base64
            string base64String = Convert.ToBase64String(memoryStream.ToArray());
            return base64String;
        }
    }
}
